import config from '../user-defined.config.js'
import store  from '../store/index.js'
  const STORAGE_COOKIE = uni.getStorageSync('COOKIE_TCL');
const {
	remote: {
		Tschool: {
			baseUrl
		}
	}
} = config



 async function  getRemote(url = '', data = {}, header = {},fixed = {}) {
	data.ts = new Date().getTime()
    header.Cookie =	 store.getters['user/cookieTclGet'] || STORAGE_COOKIE
    const request =	uni.request({
		url: `${baseUrl}${url}`,
		method: 'GET',
		data:{
			...fixed,
			...data
		},
		header
	});
	return await rebuilderResultRemote(request)
}

async function postRemote(url = '', data = {}, header = {},fixed = {}) {
	data.ts = new Date().getTime()
	header.Cookie =	 store.getters['user/cookieTclGet'] || STORAGE_COOKIE
	const request = uni.request({
		url: `${baseUrl}${url}`,
		method: 'POST',
		data:{
			...fixed,
			...data
		},
		header
	});
	return await rebuilderResultRemote(request)
}

async function rebuilderResultRemote (request){
	const { 1:{data} = [] } = await request
	  const {code} = data
	let success = false
	if(code == 0){
        success = true		
	}else{
		success = false
	}
	return {
		data, 
		success
	}
}
async function rebuilderResultCloud (request){
	const { result:{code,message:data}} = await request
	let success = false
	if(code === 0){
		success = true
	}else{
		success = false
	}
	return {
		 success,
		 data
	}
}



export default {


}

export {
	getRemote,
	postRemote,
	rebuilderResultRemote,
	rebuilderResultCloud
}

